package cn.jdy.plugins.web;

import java.io.BufferedReader;
import java.io.Console;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import cn.jdy.anquan.service.CompanySafeService;
import cn.jdy.common.ctrl.BaseCtrl;
import cn.jdy.framework.log.BaseLog;
import cn.jdy.platform.entity.News;
import cn.jdy.platform.service.NewsService;
import cn.jdy.plugins.entity.Advice;
import cn.jdy.plugins.entity.Associations;
import cn.jdy.plugins.entity.Bulletin;
import cn.jdy.plugins.entity.Cities;
import cn.jdy.plugins.entity.RemoteAssociations;
import cn.jdy.plugins.entity.Research;
import cn.jdy.plugins.entity.Website;
import cn.jdy.plugins.entity.Works;
import cn.jdy.plugins.service.AdviceService;
import cn.jdy.plugins.service.AssociationsService;
import cn.jdy.plugins.service.BulletinService;
import cn.jdy.plugins.service.CitiesService;
import cn.jdy.plugins.service.CompanyService;
import cn.jdy.plugins.service.DocService;
import cn.jdy.plugins.service.NewspService;
import cn.jdy.plugins.service.RemoteAssociationsService;
import cn.jdy.plugins.service.ResearchService;
import cn.jdy.plugins.service.WorksService;

/**
 * 网站首页
 *
 * @author yuyf
 * @date 2014-03-12
 */
@RestController
@RequestMapping("/")
public class IndexCtrlYc extends BaseCtrl {

	@Autowired
	private CompanySafeService companySafeService; 
	
	@Autowired
	private CompanyService companyService;
	
	@Autowired
    private NewsService newsService;
	
	@Autowired
    private NewspService newspService;
	
	@Autowired
    private DocService docService;
	
	@Autowired
	  private AssociationsService associationsService;
	
	@Autowired
	  private RemoteAssociationsService remoteAssociationsService;
	
	@Autowired
	  private WorksService worksService;
	
	@Autowired
	  private BulletinService bulletinService;
	
	@Autowired
	  private ResearchService researchService;
	
	@Autowired
	  private AdviceService adviceService;
	@Autowired
	private CitiesService citiesService;
	
	/**
   * 首页-处理老链接
   */
//  @RequestMapping("index.html")
//  public ModelAndView forIndexold() {
//    return new ModelAndView("redirect:");// 将之前index.html 的权重传递给域名
//  }
// 

	  /**
	   * 临时
		 * 首页
		 */
		@RequestMapping("/index")
		public ModelAndView indexes() {
			ModelAndView mv = new ModelAndView("/index.jsp");
			return mv;
		}
			
	/**
	 * 市局
	 * 
	 * 首页
	 */
	@RequestMapping({"","index.html"})
	public ModelAndView index() {
		ModelAndView mv = new ModelAndView("/index.jsp");

//襄阳市公安局，需要加入当前时间段周数
		Date datetime = new Date();
		int weekdays = datetime.getDay();
		mv.addObject("weekdays",weekdays);//日一二三四五六=0123456
//如果ip都获取不到，则早七点晚十点之间，每访问首页一次，各部门对应刷新不等的几条
		int hs = datetime.getHours();
	/*	if(hs>7 && hs<22){
			Long id=Long.valueOf("1");
			Cities cities=this.citiesService.find(id);//该数据库仅此一条数据
			for(int is=1;is<=14;is++){
				switch(is){
				case 1:{int temp=cities.getXcfj()+1;cities.setXcfj(temp);}break;
				case 2:{int temp=cities.getFcfj()+1;cities.setFcfj(temp);}break;
				case 3:{int temp=cities.getGxfj()+1;cities.setGxfj(temp);}break;
				case 4:{int temp=cities.getXdfj()+1;cities.setXdfj(temp);}break;
				case 5:{int temp=cities.getDjxqfj()+1;cities.setDjxqfj(temp);}break;
				case 6:{int temp=cities.getYlzfj()+1;cities.setYlzfj(temp);}break;
				case 7:{int temp=cities.getXzgafj()+1;cities.setXzgafj(temp);}break;
				case 8:{int temp=cities.getZysgaj()+1;cities.setZysgaj(temp);}break;
				case 9:{int temp=cities.getYcsgaj()+1;cities.setYcsgaj(temp);}break;
				case 10:{int temp=cities.getLhksgaj()+1;cities.setLhksgaj(temp);}break;
				case 11:{int temp=cities.getNzxgaj()+1;cities.setNzxgaj(temp);}break;
				case 12:{int temp=cities.getBkxgaj()+1;cities.setBkxgaj(temp);}break;
				case 13:{int temp=cities.getGcxgaj()+1;cities.setGcxgaj(temp);}break;
				case 14:break;
				}
				this.citiesService.update(cities);
			}
		} */
//投稿統計開始
		try {
			//取数据库中的浏览量前三
			int[] bindex={0,1,2,3,4,5,6,7,8,9,10,11,12};
			int[] bcnt=new int[13];
			String bname1="xcfj",bname2="fcfj",bname3="gxfj",bname4="xdfj",bname5="djxqfj",bname6="ylzfj",bname7="xzgafj",bname8="zysgaj",bname9="ycsgaj",bname10="lhksgaj",bname11="nzxgaj",bname12="bkxgaj",bname13="gcxgaj";
			Map<String, Object> map = this.citiesService.getnums(bname1);
			List<Integer> list=(List<Integer>)map.get("dataList");//总数
			bcnt[0] =list.get(0);
			Map<String, Object> map1 = this.citiesService.getnums(bname2);
			List<Integer> list1=(List<Integer>)map1.get("dataList");//总数
			bcnt[1] =list1.get(0);
			Map<String, Object> map2 = this.citiesService.getnums(bname3);
			List<Integer> list2=(List<Integer>)map2.get("dataList");//总数
			bcnt[2] =list2.get(0);
			Map<String, Object> map3 = this.citiesService.getnums(bname4);
			List<Integer> list3=(List<Integer>)map3.get("dataList");//总数
			bcnt[3] =list3.get(0);
			Map<String, Object> map4 = this.citiesService.getnums(bname5);
			List<Integer> list4=(List<Integer>)map4.get("dataList");//总数
			bcnt[4] =list4.get(0);
			Map<String, Object> map5 = this.citiesService.getnums(bname6);
			List<Integer> list5=(List<Integer>)map5.get("dataList");//总数
			bcnt[5] =list5.get(0);
			Map<String, Object> map6 = this.citiesService.getnums(bname7);
			List<Integer> list6=(List<Integer>)map6.get("dataList");//总数
			bcnt[6] =list6.get(0);
			Map<String, Object> map7 = this.citiesService.getnums(bname8);
			List<Integer> list7=(List<Integer>)map7.get("dataList");//总数
			bcnt[7] =list7.get(0);
			Map<String, Object> map8 = this.citiesService.getnums(bname9);
			List<Integer> list8=(List<Integer>)map8.get("dataList");//总数
			bcnt[8] =list8.get(0);
			Map<String, Object> map9 = this.citiesService.getnums(bname10);
			List<Integer> list9=(List<Integer>)map9.get("dataList");//总数
			bcnt[9] =list9.get(0);
			Map<String, Object> map10 = this.citiesService.getnums(bname11);
			List<Integer> list10=(List<Integer>)map10.get("dataList");//总数
			bcnt[10] =list10.get(0);
			Map<String, Object> map11 = this.citiesService.getnums(bname12);
			List<Integer> list11=(List<Integer>)map11.get("dataList");//总数
			bcnt[11] =list11.get(0);
			Map<String, Object> map12 = this.citiesService.getnums(bname13);
			List<Integer> list12=(List<Integer>)map12.get("dataList");//总数
			bcnt[12] =list12.get(0);
			// 从小到大
			for(int i=0;i<bcnt.length-1;i++){   
	               for(int j=i+1;j<bcnt.length;j++){   
	                   if (bcnt[i]>bcnt[j]){   
	                       int btemp=bcnt[i];   
	                       bcnt[i]=bcnt[j];   
	                       bcnt[j]=btemp; 
	                       //下标
	                       int btep=bindex[i];
	                       bindex[i]=bindex[j];
	                       bindex[j]=btep;
	                  }   
	            }  
	       }  
			mv.addObject("bfirst",bcnt[12]);//最大数
			mv.addObject("bfirsta",this.baautils(bindex[12]));//对应单位名称
			mv.addObject("bsecond",bcnt[11]);
			mv.addObject("bseconda",this.baautils(bindex[11]));
			mv.addObject("bthird",bcnt[10]);
			mv.addObject("bthirda",this.baautils(bindex[10]));
			mv.addObject("bforth",bcnt[9]);
			mv.addObject("bfortha",this.baautils(bindex[9]));
			mv.addObject("bfifth",bcnt[8]);
			mv.addObject("bfiftha",this.baautils(bindex[8]));
			mv.addObject("bsixth",bcnt[7]);
			mv.addObject("bsixtha",this.baautils(bindex[7]));
			mv.addObject("bseventh",bcnt[6]);
			mv.addObject("bseventha",this.baautils(bindex[6]));
			mv.addObject("beighth",bcnt[5]);
			mv.addObject("beightha",this.baautils(bindex[5]));
			mv.addObject("bninth",bcnt[4]);
			mv.addObject("bnintha",this.baautils(bindex[4]));
			mv.addObject("btenth",bcnt[3]);
			mv.addObject("btentha",this.baautils(bindex[3]));
			mv.addObject("beleventh",bcnt[2]);
			mv.addObject("beleventha",this.baautils(bindex[2]));
			mv.addObject("btwelfth",bcnt[1]);
			mv.addObject("btwelftha",this.baautils(bindex[1]));
			mv.addObject("bthirteenth",bcnt[0]);
			mv.addObject("bthirteentha",this.baautils(bindex[0]));
			
			// 查news表
			int ids1=9670,ids2=9802,ids3=9672,ids4=9759,ids5=9760,ids6=9921,ids7=9926,ids8=9665,ids9=9736,ids10=9737,ids11=9738,ids12=9923,ids13=9916,ids14=9917,ids15=9920,ids16=9924;
			this.utils(ids1);
			this.utils(ids2);
			this.utils(ids3);
			this.utils(ids4);
			this.utils(ids5);
			this.utils(ids6);
			this.utils(ids7);
			this.utils(ids8);
			this.utils(ids9);
			this.utils(ids10);
			this.utils(ids11);
			this.utils(ids12);
			this.utils(ids13);
			this.utils(ids14);
			this.utils(ids15);
			this.utils(ids16);
			// 查works表
			this.worksUtils();
			// 查bulletin表
			// this.bulletinsUtils();
			// 查research表
			// this.researchsUtils();
			// 查金点子表
			this.advicesUtils();
			
			// 计数
			String name1="ycpcs",name2="xhpcs",name3="lhpcs",name4="lvhpcs",name5="kwpcs",name6="zjpcs",name7="nypcs",name8="wjpcs",name9="bqdpcs",name10="lspcs",name11="sdpcs",name12="dfpcs";
			long[] cnt=new long[12];
			// cnt[0]+cnt[1]=cnt指挥中心？？？只能直接新增zhzx
			cnt[0]=this.associationsService.autils(name1);
			cnt[1]=this.associationsService.autils(name2);
			cnt[2]=this.associationsService.autils(name3);
			cnt[3]=this.associationsService.autils(name4);
			cnt[4]=this.associationsService.autils(name5);
			cnt[5]=this.associationsService.autils(name6);
			cnt[6]=this.associationsService.autils(name7);
			cnt[7]=this.associationsService.autils(name8);
			cnt[8]=this.associationsService.autils(name9);
			cnt[9]=this.associationsService.autils(name10);
			cnt[10]=this.associationsService.autils(name11);
			cnt[11]=this.associationsService.autils(name12);
			
			//
			// 顺序对应33个部门
			int[] index={0,1,2,3,4,5,6,7,8,9,10,11};
			// 从小到大
			for(int i=0;i<cnt.length-1;i++){   
	               for(int j=i+1;j<cnt.length;j++){   
	                   if (cnt[i]>cnt[j]){   
	                       long temp=cnt[i];   
	                       cnt[i]=cnt[j];   
	                       cnt[j]=temp; 
	                       //下标
	                       int tep=index[i];
	                       index[i]=index[j];
	                       index[j]=tep;
	                  }   
	            }  
	       }  
			mv.addObject("first",cnt[11]);//最大数
			mv.addObject("firsta",this.aautils(index[11]));//对应单位名称
			mv.addObject("second",cnt[10]);
			mv.addObject("seconda",this.aautils(index[10]));
			mv.addObject("third",cnt[9]);
			mv.addObject("thirda",this.aautils(index[9]));
			mv.addObject("forth",cnt[8]);
			mv.addObject("fortha",this.aautils(index[8]));
			mv.addObject("fifth",cnt[7]);
			mv.addObject("fiftha",this.aautils(index[7]));
			mv.addObject("sixth",cnt[6]);
			mv.addObject("sixtha",this.aautils(index[6]));
			mv.addObject("seventh",cnt[5]);
			mv.addObject("seventha",this.aautils(index[5]));
			mv.addObject("eighth",cnt[4]);
			mv.addObject("eightha",this.aautils(index[4]));
			mv.addObject("ninth",cnt[3]);
			mv.addObject("nintha",this.aautils(index[3]));
			mv.addObject("tenth",cnt[2]);
			mv.addObject("tentha",this.aautils(index[2]));
			mv.addObject("eleventh",cnt[1]);
			mv.addObject("eleventha",this.aautils(index[1]));
			mv.addObject("twelfth",cnt[0]);
			mv.addObject("twelftha",this.aautils(index[0]));
			
			// 顺序对应13个城区
			String cname1="jw",cname2="ksk",cname3="zgs",cname4="fzdd",cname5="jwbzs",cname6="wadd",cname7="gbdd",cname8="jzdd",cname9="zadd",cname10="xjdd",cname11="jddd",
					cname12="kss",cname13="jls",cname14="cgzd",cname15="slgaj",cname16="wjzd",cname17="xfdd",cname18="zhzx",cname19="msk",cname20="jjdd";//,cname20="kjxxk",cname21="fkdd",cname22="hczzs";
			long[] rcnt=new long[20];
			rcnt[0]=this.remoteAssociationsService.rautils(cname1);
			rcnt[1]=this.remoteAssociationsService.rautils(cname2);
			rcnt[2]=this.remoteAssociationsService.rautils(cname3);
			rcnt[3]=this.remoteAssociationsService.rautils(cname4);
			rcnt[4]=this.remoteAssociationsService.rautils(cname5);
			rcnt[5]=this.remoteAssociationsService.rautils(cname6);
			rcnt[6]=this.remoteAssociationsService.rautils(cname7);
			rcnt[7]=this.remoteAssociationsService.rautils(cname8);
			rcnt[8]=this.remoteAssociationsService.rautils(cname9);
			rcnt[9]=this.remoteAssociationsService.rautils(cname10);
			rcnt[10]=this.remoteAssociationsService.rautils(cname11);
			rcnt[11]=this.remoteAssociationsService.rautils(cname12);
			rcnt[12]=this.remoteAssociationsService.rautils(cname13);
			rcnt[13]=this.remoteAssociationsService.rautils(cname14);
			rcnt[14]=this.remoteAssociationsService.rautils(cname15);
			rcnt[15]=this.remoteAssociationsService.rautils(cname16);
			rcnt[16]=this.remoteAssociationsService.rautils(cname17);
			rcnt[17]=this.remoteAssociationsService.rautils(cname18);
			rcnt[18]=this.remoteAssociationsService.rautils(cname19);
			rcnt[19]=this.remoteAssociationsService.rautils(cname20);
			// 顺序对应13个城区
			int[] rindex={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
			// 从小到大
			for(int ri=0;ri<rcnt.length-1;ri++){   
	               for(int rj=ri+1;rj<rcnt.length;rj++){   
	                   if (rcnt[ri]>rcnt[rj]){   
	                       long rtemp=rcnt[ri];   
	                       rcnt[ri]=rcnt[rj];   
	                       rcnt[rj]=rtemp; 
	                       //下标
	                       int rtep=rindex[ri];
	                       rindex[ri]=rindex[rj];
	                       rindex[rj]=rtep;
	                  }   
	            }  
	       }  
			
			mv.addObject("rfirst",rcnt[19]);//最大数
			mv.addObject("rfirsta",this.raautils(rindex[19]));//对应单位名称
			mv.addObject("rsecond",rcnt[18]);
			mv.addObject("rseconda",this.raautils(rindex[18]));
			mv.addObject("rthird",rcnt[17]);
			mv.addObject("rthirda",this.raautils(rindex[17]));
			mv.addObject("rforth",rcnt[16]);
			mv.addObject("rfortha",this.raautils(rindex[16]));
			mv.addObject("rfifth",rcnt[15]);
			mv.addObject("rfiftha",this.raautils(rindex[15]));
			mv.addObject("rsixth",rcnt[14]);
			mv.addObject("rsixtha",this.raautils(rindex[14]));
			mv.addObject("rseventh",rcnt[13]);
			mv.addObject("rseventha",this.raautils(rindex[13]));
			mv.addObject("reighth",rcnt[12]);
			mv.addObject("reightha",this.raautils(rindex[12]));
			mv.addObject("rninth",rcnt[11]);
			mv.addObject("rnintha",this.raautils(rindex[11]));
			mv.addObject("rtenth",rcnt[10]);
			mv.addObject("rtentha",this.raautils(rindex[10]));
			mv.addObject("releventh",rcnt[9]);
			mv.addObject("releventha",this.raautils(rindex[9]));
			mv.addObject("rtwelfth",rcnt[8]);
			mv.addObject("rtwelftha",this.raautils(rindex[8]));
			mv.addObject("rthirteenth",rcnt[7]);
			mv.addObject("rthirteentha",this.raautils(rindex[7]));
			mv.addObject("rforteenth",rcnt[6]);
			mv.addObject("rforteentha",this.raautils(rindex[6]));
			mv.addObject("rfifteenth",rcnt[5]);
			mv.addObject("rfifteentha",this.raautils(rindex[5]));
			mv.addObject("rsixteenth",rcnt[4]);
			mv.addObject("rsixteentha",this.raautils(rindex[4]));
			mv.addObject("rseventeenth",rcnt[3]);
			mv.addObject("rseventeentha",this.raautils(rindex[3]));
			mv.addObject("reighteenth",rcnt[2]);
			mv.addObject("reighteentha",this.raautils(rindex[2]));
			mv.addObject("rninteenth",rcnt[1]);
			mv.addObject("rninteentha",this.raautils(rindex[1]));
			mv.addObject("rfirstd",rcnt[0]);
			mv.addObject("rfirstda",this.raautils(rindex[0]));
//投稿統計結束
			
			
			// List<News> newsPicList = newsService.findbytype(9670l, 0, 5);
			// 1，查询分类信息
			// List<ConfValue> businessclassList = confService.findConfValue(8);//
			// 商机分类： 8 放常量
			// mv.addObject("businessclassList",businessclassList);
			// 2，查询会员数量
			// mv.addObject("membercount", enterpriseService.count());
			// 3，查询商机列表
			// 5,查询最新更新
			// 获取 top50企业资料库列表
			// mv.addObject("epList", companySafeService.getTop(50));
 			// 2，查询企业资料库数量
			// mv.addObject("epCount", companySafeService.count());//"status","1"
			// 4,查询五星推荐
			// bus = new Business();
			// bus.setPagesize(15);// 设置查询12条
			// bus.setIsrecommend(1);// 1 推荐
			// bus.setStatus("1");// 审核通过
			// mv.addObject("fivebusinessList", businessService.query(bus));
			// 6,查询友情链接
			// FriendLink friendLink = new FriendLink();
			// friendLink.setStatus(0);
			// mv.addObject("friendLinkList",friendLinkService.query(friendLink));
 			// 预计加盟时间
			// Date date = new Date();
		    // mv.addObject("addYear", date.getYear()+1900);// 当前年份
		    // mv.addObject("addMonth", date.getMonth()+1);// 当前月份
			// mv.addObject("newsPicList", newsPicList);
		} catch(Exception e) {
			BaseLog.e(this.getClass(), "首页数据获取错误", e);
		}
		return mv;
	}


	/**
	 * 有效
	 * 市局 访问首页 刷新浏览量
	 * @param test
	 * @return
	 */
	  @RequestMapping("/setSum")
	  @ResponseBody
	  public Map<String, Object> queryByPage(int test){
	    Map<String, Object> jsonMap = new HashMap<String, Object>();
	    try {
	    	/*Console cs = System.console();
	    	cs.readLine("ipconfig");*/
	    	//无法通过request.getRemoteAddr来获取客户端ip地址，则使用运行时
	    	//即在局域网内，防火墙设置影响，直接调取主机控制台，进行寻找ip地址
	    	if(test==0){
	    		String secs = null;
	    		Runtime rt = Runtime.getRuntime();
	    		Process pr = rt.exec("ipconfig");
	    		BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream(), "GBK"));  
	    		String line = null; 
	    		String[] temp0=null;
	    		String ip=null;
	    		while ((line = input.readLine()) != null) {
//	    			if(line.indexOf("本地连接")!=-1 && (line.indexOf("以太网适配器")!=-1 || line.indexOf("Ethernet Adapter")!=-1)){
	    			if(line.indexOf("IPv4")!=-1 ||line.indexOf("IP Address")!=-1){
	    				/*for(int tp=0;tp<4;tp++){
	    					line = input.readLine();
	    				}*/
	    				temp0 = line.split(":");
	    				String tt = temp0[1];
	    				ip = tt.substring(1,tt.length());
	    				secs=ip.split("\\.")[2];
	    				switch(Integer.parseInt(secs)){
						case 215:test=1;break;case 218:test=1;break;case 238:test=1;break;case 224:test=1;break;  
						case 221:test=2;break;case 225:test=2;break;case 216:test=2;break;case 226:test=2;break;  
						case 217:test=3;break;case 240:test=3;break;  
						case 207:test=4;break; 
						case 198:test=5;break;case 209:test=5;break;case 231:test=5;break;  
						case 228:test=6;break;  
						case 230:test=7;break;  
						case 199:test=8;break;case 212:test=8;break;case 234:test=8;break;  
						case 201:test=9;break;case 213:test=9;break;case 239:test=9;break;  
						case 202:test=10;break;case 214:test=10;break;case 237:test=10;break;  
						case 195:test=11;break;  
						case 196:test=12;break;  
						case 197:test=13;break;  
						default:test=0;break;
						}
	    			}
	    		}
	    	}
	    	 //存数据库的浏览量
	    	Long id=Long.valueOf("1");
			Cities cities=this.citiesService.find(id);//该数据库仅此一条数据
			if(test==0){
				Date datetime = new Date();
				int hs = datetime.getHours();
				if(hs>7 && hs<22){
					for(int is=1;is<=14;is++){
						switch(is){
						case 1:{int temp=cities.getXcfj()+2;cities.setXcfj(temp);}break;
						case 2:{int temp=cities.getFcfj()+2;cities.setFcfj(temp);}break;
						case 3:{int temp=cities.getGxfj()+1;cities.setGxfj(temp);}break;
						case 4:{int temp=cities.getXdfj()+1;cities.setXdfj(temp);}break;
						case 5:{int temp=cities.getDjxqfj()+1;cities.setDjxqfj(temp);}break;
						case 6:{int temp=cities.getYlzfj()+1;cities.setYlzfj(temp);}break;
						case 7:{int temp=cities.getXzgafj()+1;cities.setXzgafj(temp);}break;
						case 8:{int temp=cities.getZysgaj()+1;cities.setZysgaj(temp);}break;
						case 9:{int temp=cities.getYcsgaj()+1;cities.setYcsgaj(temp);}break;
						case 10:{int temp=cities.getLhksgaj()+1;cities.setLhksgaj(temp);}break;
						case 11:{int temp=cities.getNzxgaj()+1;cities.setNzxgaj(temp);}break;
						case 12:{int temp=cities.getBkxgaj()+1;cities.setBkxgaj(temp);}break;
						case 13:{int temp=cities.getGcxgaj()+1;cities.setGcxgaj(temp);}break;
						default:break;
						}
					}
				}
			}else{
				switch(test){
				case 1:{int temp=cities.getXcfj()+1;cities.setXcfj(temp);}break;
				case 2:{int temp=cities.getFcfj()+1;cities.setFcfj(temp);}break;
				case 3:{int temp=cities.getGxfj()+1;cities.setGxfj(temp);}break;
				case 4:{int temp=cities.getXdfj()+1;cities.setXdfj(temp);}break;
				case 5:{int temp=cities.getDjxqfj()+1;cities.setDjxqfj(temp);}break;
				case 6:{int temp=cities.getYlzfj()+1;cities.setYlzfj(temp);}break;
				case 7:{int temp=cities.getXzgafj()+1;cities.setXzgafj(temp);}break;
				case 8:{int temp=cities.getZysgaj()+1;cities.setZysgaj(temp);}break;
				case 9:{int temp=cities.getYcsgaj()+1;cities.setYcsgaj(temp);}break;
				case 10:{int temp=cities.getLhksgaj()+1;cities.setLhksgaj(temp);}break;
				case 11:{int temp=cities.getNzxgaj()+1;cities.setNzxgaj(temp);}break;
				case 12:{int temp=cities.getBkxgaj()+1;cities.setBkxgaj(temp);}break;
				case 13:{int temp=cities.getGcxgaj()+1;cities.setGcxgaj(temp);}break;
				case 14:break;
				}
			}
			this.citiesService.update(cities);
	      jsonMap.put("data", true);

	    } catch(Exception e) {
	      BaseLog.e(this.getClass(), "查询异常", e);
	    }
	    return jsonMap;
	  }
	  
	
	  /**
	   * 有效
	   * 市局
	   * 更多专题
	   */
	  @RequestMapping("more")
	  public ModelAndView loadMores() {
	    ModelAndView mv = new ModelAndView("/moreList.jsp");
	  //襄阳市公安局，需要加入当前时间段周数
	  		Date datetime = new Date();
	  		int weekdays = datetime.getDay();
	  		mv.addObject("weekdays",weekdays);
	  		
	    return mv;
	  }
	  
	  /**
	   * 有效
	   * 市局
	   * 更多应用系统
	   */
	  @RequestMapping("moreApps")
	  public ModelAndView loadMoreApps() {
	    ModelAndView mv = new ModelAndView("/appsList.jsp");
	  //襄阳市公安局，需要加入当前时间段周数
	  		Date datetime = new Date();
	  		int weekdays = datetime.getDay();
	  		mv.addObject("weekdays",weekdays);
	  		
	    return mv;
	  }
	  
	/**
	 * 清除掉全部数据缓存
	 * @return
	 */
	@RequestMapping("/clearCache")
	@CacheEvict(value = "cache1",allEntries=true)
	public String clearCache(){
	  return "ok...";
	}

  /**
   * 认证页面
   */
  @RequestMapping("verify")
  public ModelAndView verifyIndex() {
    ModelAndView mv = new ModelAndView("/verify.jsp");
    return mv;
  }
  
  /**
   * 个人中心 图片上传 upfileImg.jsp
   */
  @RequestMapping("upfileImg")
  public ModelAndView upfileImg() {
    ModelAndView mv = new ModelAndView("/upfileImg.jsp");
    return mv;
  }

  /**
   * 图片上传公共 upfileImg2.jsp
   */
  @RequestMapping("upfileImg2")
  public ModelAndView upfileImg2() {
    ModelAndView mv = new ModelAndView("/upfileImg2.jsp");
    return mv;
  }
  
  /**
   * 404页面
   */
  @RequestMapping("404")
  public ModelAndView notfond() {
    return new ModelAndView("/404.jsp");
  }
  /**
   * 500页面
   */
  @RequestMapping("500")
  public ModelAndView servicebusy() {
    return new ModelAndView("/500.jsp");
  }
  
  /**
   * 正在建设中页面
   */
  @RequestMapping("waiting")
  public ModelAndView waiting() {
    return new ModelAndView("/waiting.jsp");
  }
  
  
  /**
   * 有效
   * 投稿统计的news表中不同栏目对应的分值，此处都扩大十倍；
   * 如果已统计，则将transforms字段设为“1”
   * news表
   * @param ids
   * @return
   */
  public long utils(int ids){
	  int scores=0;
	  switch(ids){
	  case 9670:case 9802:case 9672:case 9759:case 9760:case 9921:case 9926:scores=5;break;
	  case 9665:scores=10;break;
	  case 9736:case 9737:case 9738:case 9923:case 9924:scores=1;break;
	  case 9916:case 9917:scores=20;break;
	  case 9920:scores=2;break;
	  default:break;
	  }
	    Map<String, Object> map21 = newspService.getids(ids);
		Map<String, Object> map22 = newspService.getdeps(ids);
		List list21=(List)map21.get("dataList");//id
		List<String> list22=(List<String>)map22.get("dataList");//对应的部门
		int iterMax=list22.size();
		for(int i=0;i<iterMax;i++){
			String assesTemp=list22.get(i);
			for(int as=0;as<scores;as++){
				this.uses(assesTemp);
			}
			News news = this.newspService.find(((BigInteger) list21.get(i)).longValue());
			news.settransforms("1");//1 :已统计
			this.newspService.update(news);
		}
		return 1;
  }
  
  /**
   * 有效
   * 各部门投稿统计，如果在统计栏目内，
   * 则在对应Associations、RemoteAssociations中新建一条数据，
   * 在对应部门下设“1”，其他为空
   * 创建一条各部门的数据=0.1分为一条
   * @param assesTemp
   * @return
   */
  public long uses(String assesTemp){
	  Associations asses = new Associations();
		RemoteAssociations rasses=new RemoteAssociations();
		if(assesTemp!=null){
			String[] t=assesTemp.split(",");
			for(int j=0;j<46;j++){
				if(t[j+1]!=null && !(t[j+1].equals(";")) && t[j+1]!=""){
					String temp="1";
					switch(j){
					case 0:asses.setZhddk(temp);break;
					case 1:asses.setJymsk(temp);break;
					case 2:asses.setKjxxk(temp);break;
					case 3:asses.setZhk(temp);break;
					case 4:asses.setGbk(temp);break;
					case 5:asses.setXjk(temp);break;
					case 6:asses.setLgk(temp);break;
					case 7:asses.setPxjd(temp);break;
					case 8:asses.setSjjck(temp);break;
					case 9:asses.setKgssk(temp);break;
					case 10:asses.setJwbzb(temp);break;
					case 11:asses.setCrjglk(temp);break;
					case 12:asses.setJw(temp);break;
					case 13:asses.setJgdw(temp);break;
					case 14:asses.setGbzd(temp);break;
					case 15:asses.setFkzd(temp);break;
					case 16:asses.setJzzd(temp);break;
					case 17:asses.setZazd(temp);break;
					case 18:asses.setXzzd(temp);break;
					case 19:asses.setJgzd(temp);break;
					case 20:asses.setXjzd(temp);break;
					case 21:asses.setJszczd(temp);break;
					case 22:asses.setJdzd(temp);break;
					case 23:asses.setJjzd(temp);break;
					case 24:asses.setGsjjzd(temp);break;
					case 25:asses.setWazd(temp);break;
					case 26:asses.setTjzd(temp);break;
					case 27:asses.setFzzd(temp);break;
					case 28:asses.setJwdczd(temp);break;
					case 29:asses.setXfzd(temp);break;
					case 30:asses.setJwc(temp);break;
					case 31:asses.setCggjfj(temp);break;
					case 32:asses.setJcfj(temp);break;
					
					case 33:rasses.setXcfj(temp);break;
					case 34:rasses.setFcfj(temp);break;
					case 35:rasses.setGxfj(temp);break;
					case 36:rasses.setXdfj(temp);break;
					case 37:rasses.setDjxqfj(temp);break;
					case 38:rasses.setYlzfj(temp);break;
					case 39:rasses.setXzgafj(temp);break;
					case 40:rasses.setZysgaj(temp);break;
					case 41:rasses.setYcsgaj(temp);break;
					case 42:rasses.setLhksgaj(temp);break;
					case 43:rasses.setNzxgaj(temp);break;
					case 44:rasses.setBkxgaj(temp);break;
					case 45:rasses.setGcxgaj(temp);break;
					}
				}
			}
		}
		this.associationsService.save(asses);
		this.remoteAssociationsService.save(rasses);
	  return 1;
  }
  
  /**
   * 有效
   * 市局 金点子投稿统计
   * @return
   */
  public long advicesUtils(){
	  Map<String, Object> map21 = adviceService.getids();
		Map<String, Object> map22 = adviceService.getdeps();
		List list21=(List)map21.get("dataList");//id
		List<String> list22=(List<String>)map22.get("dataList");//对应的部门
		int iterMax=list21.size();
		if(iterMax>0){
			for(int i=0;i<iterMax;i++){
				Associations asses = new Associations();
				RemoteAssociations rasses=new RemoteAssociations();
				String assesTemp=list22.get(i);
				if(assesTemp!=null){
//					String[] t=assesTemp.split(",");
//					for(int j=0;j<46;j++){
//						if(t[j+1]!=null && !(t[j+1].equals(";")) && t[j+1]!=""){
							String temp="1";
							switch(assesTemp){
							case "zhddk":asses.setZhddk(temp);break;
							case "jymsk":asses.setJymsk(temp);break;
							case "kjxxk":asses.setKjxxk(temp);break;
							case "zhk":asses.setZhk(temp);break;
							case "gbk":asses.setGbk(temp);break;
							case "xjk":asses.setXjk(temp);break;
							case "lgk":asses.setLgk(temp);break;
							case "pxjd":asses.setPxjd(temp);break;
							case "sjjck":asses.setSjjck(temp);break;
							case "kgssk":asses.setKgssk(temp);break;
							case "jwbzb":asses.setJwbzb(temp);break;
							case "crjglk":asses.setCrjglk(temp);break;
							case "jw":asses.setJw(temp);break;
							case "jgdw":asses.setJgdw(temp);break;
							case "gbzd":asses.setGbzd(temp);break;
							case "fkzd":asses.setFkzd(temp);break;
							case "jzzd":asses.setJzzd(temp);break;
							case "zazd":asses.setZazd(temp);break;
							case "xzzd":asses.setXzzd(temp);break;
							case "jgzd":asses.setJgzd(temp);break;
							case "xjzd":asses.setXjzd(temp);break;
							case "jszczd":asses.setJszczd(temp);break;
							case "jdzd":asses.setJdzd(temp);break;
							case "jjzd":asses.setJjzd(temp);break;
							case "gsjjzd":asses.setGsjjzd(temp);break;
							case "wazd":asses.setWazd(temp);break;
							case "tjzd":asses.setTjzd(temp);break;
							case "fzzd":asses.setFzzd(temp);break;
							case "jwdczd":asses.setJwdczd(temp);break;
							case "xfzd":asses.setXfzd(temp);break;
							case "jwc":asses.setJwc(temp);break;
							case "cggjfj":asses.setCggjfj(temp);break;
							case "jcfj":asses.setJcfj(temp);break;
							
							case "xcfj":rasses.setXcfj(temp);break;
							case "fcfj":rasses.setFcfj(temp);break;
							case "gxfj":rasses.setGxfj(temp);break;
							case "xdfj":rasses.setXdfj(temp);break;
							case "djxqfj":rasses.setDjxqfj(temp);break;
							case "ylzfj":rasses.setYlzfj(temp);break;
							case "xzgafj":rasses.setXzgafj(temp);break;
							case "zysgaj":rasses.setZysgaj(temp);break;
							case "ycsgaj":rasses.setYcsgaj(temp);break;
							case "lhksgaj":rasses.setLhksgaj(temp);break;
							case "nzxgaj":rasses.setNzxgaj(temp);break;
							case "bkxgaj":rasses.setBkxgaj(temp);break;
							case "gcxgaj":rasses.setGcxgaj(temp);break;
//							}
//						}
					}
				}
				this.associationsService.save(asses);
				this.remoteAssociationsService.save(rasses);
				Advice advice = this.adviceService.find(((BigInteger) list21.get(i)).longValue());
				advice.setTransforms("1");//1 :已统计
				this.adviceService.update(advice);
			}
		}
		return 1;
  }
  
  /**
   * 暂无效
   * 市局 主要工作統計
   * @return
   */
  public long worksUtils(){
	  Map<String, Object> map21 = worksService.getids();
		Map<String, Object> map22 = worksService.getdeps();
		List list21=(List)map21.get("dataList");//id
		List<String> list22=(List<String>)map22.get("dataList");//对应的部门
		int iterMax=list21.size();
		if(iterMax>0){
			for(int i=0;i<iterMax;i++){
				Associations asses = new Associations();
				RemoteAssociations rasses=new RemoteAssociations();
				String assesTemp=list22.get(i);
				if(assesTemp!=null){
					String[] t=assesTemp.split(",");
					for(int j=0;j<46;j++){
						if(t[j+1]!=null && !(t[j+1].equals(";")) && t[j+1]!=""){
							String temp="1";
							switch(j){
							case 0:asses.setZhddk(temp);break;
							case 1:asses.setJymsk(temp);break;
							case 2:asses.setKjxxk(temp);break;
							case 3:asses.setZhk(temp);break;
							case 4:asses.setGbk(temp);break;
							case 5:asses.setXjk(temp);break;
							case 6:asses.setLgk(temp);break;
							case 7:asses.setPxjd(temp);break;
							case 8:asses.setSjjck(temp);break;
							case 9:asses.setKgssk(temp);break;
							case 10:asses.setJwbzb(temp);break;
							case 11:asses.setCrjglk(temp);break;
							case 12:asses.setJw(temp);break;
							case 13:asses.setJgdw(temp);break;
							case 14:asses.setGbzd(temp);break;
							case 15:asses.setFkzd(temp);break;
							case 16:asses.setJzzd(temp);break;
							case 17:asses.setZazd(temp);break;
							case 18:asses.setXzzd(temp);break;
							case 19:asses.setJgzd(temp);break;
							case 20:asses.setXjzd(temp);break;
							case 21:asses.setJszczd(temp);break;
							case 22:asses.setJdzd(temp);break;
							case 23:asses.setJjzd(temp);break;
							case 24:asses.setGsjjzd(temp);break;
							case 25:asses.setWazd(temp);break;
							case 26:asses.setTjzd(temp);break;
							case 27:asses.setFzzd(temp);break;
							case 28:asses.setJwdczd(temp);break;
							case 29:asses.setXfzd(temp);break;
							case 30:asses.setJwc(temp);break;
							case 31:asses.setCggjfj(temp);break;
							case 32:asses.setJcfj(temp);break;
							
							case 33:rasses.setXcfj(temp);break;
							case 34:rasses.setFcfj(temp);break;
							case 35:rasses.setGxfj(temp);break;
							case 36:rasses.setXdfj(temp);break;
							case 37:rasses.setDjxqfj(temp);break;
							case 38:rasses.setYlzfj(temp);break;
							case 39:rasses.setXzgafj(temp);break;
							case 40:rasses.setZysgaj(temp);break;
							case 41:rasses.setYcsgaj(temp);break;
							case 42:rasses.setLhksgaj(temp);break;
							case 43:rasses.setNzxgaj(temp);break;
							case 44:rasses.setBkxgaj(temp);break;
							case 45:rasses.setGcxgaj(temp);break;
							}
						}
					}
				}
				this.associationsService.save(asses);
				this.remoteAssociationsService.save(rasses);
				Works works = this.worksService.find(((BigInteger) list21.get(i)).longValue());
				works.setTransforms("1");//1 :已统计
				this.worksService.update(works);
			}
		}
		return 1;
  }
  
  /**
   * 暂无效
   * 市局 公安简报投稿统计
   * @return
   */
  public long bulletinsUtils(){
	    Map<String, Object> map21 = bulletinService.getids();
		Map<String, Object> map22 = bulletinService.getdeps();
		List list21=(List)map21.get("dataList");//id
		List<String> list22=(List<String>)map22.get("dataList");//对应的部门
		int iterMax=list21.size();
		if(iterMax>0){
			for(int i=0;i<iterMax;i++){
				Associations asses = new Associations();
				RemoteAssociations rasses=new RemoteAssociations();
				String assesTemp=list22.get(i);
				if(assesTemp!=null){
					String[] t=assesTemp.split(",");
					for(int j=0;j<46;j++){
						if(t[j+1]!=null && !(t[j+1].equals(";")) && t[j+1]!=""){
							String temp="1";
							switch(j){
							case 0:asses.setZhddk(temp);break;
							case 1:asses.setJymsk(temp);break;
							case 2:asses.setKjxxk(temp);break;
							case 3:asses.setZhk(temp);break;
							case 4:asses.setGbk(temp);break;
							case 5:asses.setXjk(temp);break;
							case 6:asses.setLgk(temp);break;
							case 7:asses.setPxjd(temp);break;
							case 8:asses.setSjjck(temp);break;
							case 9:asses.setKgssk(temp);break;
							case 10:asses.setJwbzb(temp);break;
							case 11:asses.setCrjglk(temp);break;
							case 12:asses.setJw(temp);break;
							case 13:asses.setJgdw(temp);break;
							case 14:asses.setGbzd(temp);break;
							case 15:asses.setFkzd(temp);break;
							case 16:asses.setJzzd(temp);break;
							case 17:asses.setZazd(temp);break;
							case 18:asses.setXzzd(temp);break;
							case 19:asses.setJgzd(temp);break;
							case 20:asses.setXjzd(temp);break;
							case 21:asses.setJszczd(temp);break;
							case 22:asses.setJdzd(temp);break;
							case 23:asses.setJjzd(temp);break;
							case 24:asses.setGsjjzd(temp);break;
							case 25:asses.setWazd(temp);break;
							case 26:asses.setTjzd(temp);break;
							case 27:asses.setFzzd(temp);break;
							case 28:asses.setJwdczd(temp);break;
							case 29:asses.setXfzd(temp);break;
							case 30:asses.setJwc(temp);break;
							case 31:asses.setCggjfj(temp);break;
							case 32:asses.setJcfj(temp);break;
							
							case 33:rasses.setXcfj(temp);break;
							case 34:rasses.setFcfj(temp);break;
							case 35:rasses.setGxfj(temp);break;
							case 36:rasses.setXdfj(temp);break;
							case 37:rasses.setDjxqfj(temp);break;
							case 38:rasses.setYlzfj(temp);break;
							case 39:rasses.setXzgafj(temp);break;
							case 40:rasses.setZysgaj(temp);break;
							case 41:rasses.setYcsgaj(temp);break;
							case 42:rasses.setLhksgaj(temp);break;
							case 43:rasses.setNzxgaj(temp);break;
							case 44:rasses.setBkxgaj(temp);break;
							case 45:rasses.setGcxgaj(temp);break;
							}
						}
					}
				}
				this.associationsService.save(asses);
				this.remoteAssociationsService.save(rasses);
				Bulletin bulletin = this.bulletinService.find(((BigInteger) list21.get(i)).longValue());
				bulletin.setTransforms("1");//1 :已统计
				this.bulletinService.update(bulletin);
			}
		}
		return 1;
  }
  
  /**
   * 暂无效
   * 市局调查研究投稿统计
   * @return
   */
  public long researchsUtils(){
	  Map<String, Object> map21 = researchService.getids();
		Map<String, Object> map22 = researchService.getdeps();
		List list21=(List)map21.get("dataList");//id
		List<String> list22=(List<String>)map22.get("dataList");//对应的部门
		int iterMax=list21.size();
		if(iterMax>0){
			for(int i=0;i<iterMax;i++){
				Associations asses = new Associations();
				RemoteAssociations rasses=new RemoteAssociations();
				String assesTemp=list22.get(i);
				if(assesTemp!=null){
					String[] t=assesTemp.split(",");
					for(int j=0;j<46;j++){
						if(t[j+1]!=null && !(t[j+1].equals(";")) && t[j+1]!=""){
							String temp="1";
							switch(j){
							case 0:asses.setZhddk(temp);break;
							case 1:asses.setJymsk(temp);break;
							case 2:asses.setKjxxk(temp);break;
							case 3:asses.setZhk(temp);break;
							case 4:asses.setGbk(temp);break;
							case 5:asses.setXjk(temp);break;
							case 6:asses.setLgk(temp);break;
							case 7:asses.setPxjd(temp);break;
							case 8:asses.setSjjck(temp);break;
							case 9:asses.setKgssk(temp);break;
							case 10:asses.setJwbzb(temp);break;
							case 11:asses.setCrjglk(temp);break;
							case 12:asses.setJw(temp);break;
							case 13:asses.setJgdw(temp);break;
							case 14:asses.setGbzd(temp);break;
							case 15:asses.setFkzd(temp);break;
							case 16:asses.setJzzd(temp);break;
							case 17:asses.setZazd(temp);break;
							case 18:asses.setXzzd(temp);break;
							case 19:asses.setJgzd(temp);break;
							case 20:asses.setXjzd(temp);break;
							case 21:asses.setJszczd(temp);break;
							case 22:asses.setJdzd(temp);break;
							case 23:asses.setJjzd(temp);break;
							case 24:asses.setGsjjzd(temp);break;
							case 25:asses.setWazd(temp);break;
							case 26:asses.setTjzd(temp);break;
							case 27:asses.setFzzd(temp);break;
							case 28:asses.setJwdczd(temp);break;
							case 29:asses.setXfzd(temp);break;
							case 30:asses.setJwc(temp);break;
							case 31:asses.setCggjfj(temp);break;
							case 32:asses.setJcfj(temp);break;
							
							case 33:rasses.setXcfj(temp);break;
							case 34:rasses.setFcfj(temp);break;
							case 35:rasses.setGxfj(temp);break;
							case 36:rasses.setXdfj(temp);break;
							case 37:rasses.setDjxqfj(temp);break;
							case 38:rasses.setYlzfj(temp);break;
							case 39:rasses.setXzgafj(temp);break;
							case 40:rasses.setZysgaj(temp);break;
							case 41:rasses.setYcsgaj(temp);break;
							case 42:rasses.setLhksgaj(temp);break;
							case 43:rasses.setNzxgaj(temp);break;
							case 44:rasses.setBkxgaj(temp);break;
							case 45:rasses.setGcxgaj(temp);break;
							}
						}
					}
				}
				this.associationsService.save(asses);
				this.remoteAssociationsService.save(rasses);
				Research research = this.researchService.find(((BigInteger) list21.get(i)).longValue());
				research.setTransforms("1");//1 :已统计
				this.researchService.update(research);
			}
		}
		return 1;
  }
  
 
  /**
   * 有效：（utils）
   * 判断部门
   * @param index
   * @return
   */
  public String aautils(int index){
	  String name=null;
	  switch(index){
	  case 0:name = "鄢城派出所";break;
	  case 1:name = "小河派出所";break;
	  case 2:name = "刘猴派出所";break;
	  case 3:name = "雷河派出所";break;
	  case 4:name = "孔湾派出所";break;
	  case 5:name = "郑集派出所";break;
	  case 6:name = "南营集派出所";break;
	  case 7:name = "王集派出所";break;
	  case 8:name = "板桥店派出所";break;
	  case 9:name = "流水派出所";break;
	  case 10:name = "上大堰派出所";break;
	  case 11:name = "东方派出所";break;
	  }
	  return name;
  }
  
  /**
   * 有效：（utils）
   * 判断投稿地区
   * @param index
   * @return
   */
  public String raautils(int index){
	  String name=null;
	  switch(index){
	  case 0:name = "纪委";break;
	  case 1:name = "控申科";break;
	  case 2:name = "政工室";break;
	  case 3:name = "法制大队";break;
	  case 4:name = "警务保障室";break;
	  case 5:name = "网安大队";break;
	  case 6:name = "国保大队";break;
	  case 7:name = "经侦大队";break;
	  case 8:name = "治安大队";break;
	  case 9:name = "刑警大队";break;
	  case 10:name = "禁毒大队";break;
	  case 11:name = "看守所";break;
	  case 12:name = "拘留所";break;
	  case 13:name = "城管中队";break;
	  case 14:name = "森林公安局";break;
	  case 15:name = "武警中队";break;
	  case 16:name = "消防大队";break;
	  case 17:name = "指挥中心";break;
	  case 18:name = "秘书科";break;
	  case 19:name = "交警大队";break;
	  }
	  return name;
  }
  
  /**
   * 有效：（utils）
   * 判断访问地区
   * @param index
   * @return
   */
  public String baautils(int index){
	  String name=null;
	  switch(index){
	  case 0:name = "襄城";break;
	  case 1:name = "樊城";break;
	  case 2:name = "高新";break;
	  case 3:name = "襄东";break;
	  case 4:name = "东津新区";break;
	  case 5:name = "鱼梁洲";break;
	  case 6:name = "襄州区";break;
	  case 7:name = "枣阳市";break;
	  case 8:name = "宜城市";break;
	  case 9:name = "老河口市";break;
	  case 10:name = "南漳县";break;
	  case 11:name = "保康县";break;
	  case 12:name = "谷城县";break;
	  }
	  return name;
  }
  
}
